package org.mriassl.service.user.service.impl;

import java.util.List;

import org.mriassl.service.user.service.BaseService;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import tk.mybatis.mapper.common.Mapper;


public abstract class BaseServiceImpl<T> implements BaseService<T> {

    protected abstract Mapper<T> getMapper();

    @Override
    public int insert(T entity){
        return getMapper().insert(entity);
    }

    @Override
    public int delete(T entity){
        return getMapper().delete(entity);
    }
    
    @Override
    public int deleteByKey(Object key){
        return getMapper().deleteByPrimaryKey(key);
    }

    @Override
    public int update(T entity) {
        return getMapper().updateByPrimaryKey(entity);
    }
    
    @Override
    @Transactional(readOnly=true, propagation=Propagation.NOT_SUPPORTED)
    public T getByKey(Object key) {
        return getMapper().selectByPrimaryKey(key);
    }
    
    @Override
    @Transactional(readOnly=true, propagation=Propagation.NOT_SUPPORTED)
    public List<T> getByCondition(T entity) {
        return getMapper().select(entity);
    }
    
    @Override
    @Transactional(readOnly=true, propagation=Propagation.NOT_SUPPORTED)
    public int getCountByCondition(T entity) {
        return getMapper().selectCount(entity);
    }
}